import type { FileInfo, ResultList, ResultOne } from '@/index.d';
import { api, urls } from '@/index';

export const deleteFileInfo = async (
  key: 'physicalDeleteByUid' | 'physicalDeleteByKeyWord',
  value: string | number
) => {
  const res = await api({
    method: 'delete',
    url: `${urls.fileInfo}/${key}/${value}`
  });
  return res.data.body;
};

//根据keyword查询一个文件
export const getFileInfoByKeyWord = async (keyword: string) => {
  try {
    const res = await api({ method: 'get', url: '/base/file/fileInfo/getOne/keyWord/' + keyword });
    if (res.status === 200) {
      const resData: ResultOne<FileInfo> = res.data;
      return resData.body;
    } else {
      ElMessage.error(res.statusText);
    }
  } catch (error) {
    ElMessage.error('获取失败，错误信息是：' + error);
  }
};

//根据keyword查询一批文件
export const getFileInfoListByKeyWord = async (keyword: string) => {
  try {
    const res = await api({ method: 'get', url: '/base/file/fileInfo/getList/keyWord/' + keyword });
    if (res.status === 200) {
      const resData: ResultList<FileInfo> = res.data;
      return resData.body;
    } else {
      ElMessage.error(res.statusText);
    }
  } catch (error) {
    ElMessage.error('获取失败，错误信息是：' + error);
  }
};
